package org.chen.web.controller;

import org.chen.model.entity.Employees;
import org.chen.model.service.EmployeesService;
import org.chen.utils.ResultJson;
import org.chen.utils.TokenUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

@Controller
@RequestMapping(value = "employees")
public class EmployeesController extends BaseController<Employees> {

	@Autowired
	private EmployeesService employeesService;

	@RequestMapping(value = "login", method = RequestMethod.GET)
	public String tologin() {
		return "login";
	}

	@ResponseBody
	@RequestMapping(value = "login", method = RequestMethod.POST)
	public ResultJson dologin(@RequestBody Employees employees) {
		ResultJson json = new ResultJson();
		employees.setEpwd(TokenUtils.genaratePwd(employees.getEaccount(), employees.getEpwd()));
		employees = employeesService.login(employees);
		if (employees != null) {
			json.setMsgcode(200);
			json.setMsginfo("success");
			json.setResult(employees);
		}
		return json;
	}
}
